/*
 JQuery EasyUI 1.5.x of Insdep Theme 1.0.0 RC2
 演示地址：https://www.insdep.com/example/
 下载地址：https://www.insdep.com
 问答地址：https://bbs.insdep.com

 项目地址：http://git.oschina.net/weavors/JQuery-EasyUI-1.5.x-Of-Insdep-Theme

 QQ交流群：184075694 （优先发布更新主题及内测包）
 */


/*初始化*/
//待修复 组件设置label后，高度失效问题
$.extend($.fn.tabs.defaults, {tabHeight: 36});
$.extend($.fn.textbox.defaults, {height: 32});
$.extend($.fn.passwordbox.defaults, {height: 32});
$.extend($.fn.combo.defaults, {height: 32});
$.extend($.fn.combobox.defaults, {height: 32});
$.extend($.fn.combogrid.defaults, {height: 32});
$.extend($.fn.combotree.defaults, {height: 32});
$.extend($.fn.combotreegrid.defaults, {height: 32});

$.extend($.messager.defaults, {width: 320});


$.extend($.fn.datebox.defaults, {
    height: 32,
    panelWidth: 220
    /*
     此处待修复，无法选择日期错误
     ,
     formatter:function(date){
     var y = date.getFullYear();
     var m = date.getMonth()+1;
     var d = date.getDate();
     return y+"年"+m+"月"+d+"日";
     }*/
});
$.extend($.fn.datetimebox.defaults, {
    height: 32,
    panelWidth: 220
    /*
     此处待修复，无法选择日期错误
     ,
     formatter:function(date){
     var y = date.getFullYear();
     var m = date.getMonth()+1;
     var d = date.getDate();
     var H = date.getHours();       //获取当前小时数(0-23)
     var i = date.getMinutes();     //获取当前分钟数(0-59)
     var s = date.getSeconds();     //获取当前秒数(0-59)
     return y+"年"+m+"月"+d+"日 "+H+":"+i+":"+s;
     }*/
});
$.extend($.fn.datetimespinner.defaults, {height: 32});
$.extend($.fn.numberbox.defaults, {height: 32});
$.extend($.fn.spinner.defaults, {height: 32});


$.extend($.fn.numberspinner.defaults, {height: 32});//上线数字不能使用
$.extend($.fn.searchbox.defaults, {height: 32});
$.extend($.fn.filebox.defaults, {height: 32});

$.extend($.fn.validatebox.defaults, {height: 32});
$.extend($.fn.validatebox.defaults.tipOptions, {
    onShow: function () {
        $(this).tooltip("tip").css({
            display: 'none',
            color: "#fff",
            border: "none",
            backgroundColor: "#ff7e00"
        });
    }
}); //重置tipOptions的样式
$.extend($.fn.validatebox.defaults.rules, {
    postCode: {
        validator: function (value) {
            return /^[1-9]\d{5}(?!\d)$/.test(value);
        },
        message: '请输入有效的邮政编码！'
    },
    telephone: {
        validator: function (value) {
            return /^([0-9]{3,4}-)?[0-9]{7,8}$/.test(value);
        },
        message: '请输入有效的电话号码！'
    },
    mobilePhone: {
        validator: function (value) {
            return /^((\+?86)|(\+86))?(13[012356789][0-9]{8}|15[012356789][0-9]{8}|18[02356789][0-9]{8}|147[0-9]{8}|1349[0-9]{7})$/.test(value);
        },
        message: '请输入有效的手机号码！'
    },
    startDateCompare: {
        validator: function (value, param) {
            var end = param[0];
            if (typeof end === 'string') {
                end = $(param[0]);//结束日期 selector
            }
            if (typeof end.data('combo') === 'undefined' || !end.datebox("getValue")) {
                return true;
            }
            var endDate = new Date(end.datebox("getValue"));
            var CurDate = new Date(value);
            return CurDate < endDate;
        },
        message: '开始日期必须小于结束日期！'
    },
    endDateCompare: {
        validator: function (value, param) {
            var start = param[0];
            if (typeof start === 'string') {
                start = $(param[0]); //开始日期 selector
            }
            if (typeof start.data('combo') === 'undefined' || !start.datebox("getValue") || !value) {
                return true;
            }
            var startDate = new Date(start.datebox("getValue"));
            var CurDate = new Date(value);
            return CurDate > startDate;
        },
        message: '结束日期必须大于开始日期！'
    },
    idcn: {
        validator: function (value) {
            return /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/.test(value);
        },
        message: '请输入有效的身份证号码！'
    }
});
var easyuiErrorFunction = function () {
    layer.alert('数据出现异常！', {
        title: '请求失败',
        icon: 2,
        shade: [0.5, '#ffffff']
    });
};
$.fn.datagrid.defaults.onLoadError = easyuiErrorFunction;
$.fn.treegrid.defaults.onLoadError = easyuiErrorFunction;
$.fn.tree.defaults.onLoadError = easyuiErrorFunction;
$.fn.combogrid.defaults.onLoadError = easyuiErrorFunction;
$.fn.combobox.defaults.onLoadError = easyuiErrorFunction;
$.fn.form.defaults.onLoadError = easyuiErrorFunction;
$.fn.datagrid.defaults.pageSize = 20;

